Skip to content

Conversation

@xxchan
Copy link

@xxchan xxchan commented Sep 9, 2023

The merge conflict resolution diff:

❯ git show f989f42 
commit f989f421ad2d56a869e5bebca0219d179e3ecf0c (HEAD -> madsim, xxchan/madsim)
Merge: 4538cd6b c5ff8cfd
Author: xxchan <xxchan22f@gmail.com>
Date:   Sun Sep 10 00:08:13 2023 +0800

    Merge branch 'master' into madsim

diff --cc tokio-postgres/Cargo.toml
index e6c7b4f7,ec5e3cbe..fefaddd0
--- a/tokio-postgres/Cargo.toml
+++ b/tokio-postgres/Cargo.toml
@@@ -53,17 -54,21 +54,21 @@@ parking_lot = "0.12
  percent-encoding = "2.0"
  pin-project-lite = "0.2"
  phf = "0.11"
- postgres-protocol = { version = "0.6.4" }
- postgres-types = { version = "0.2.4" }
- socket2 = { version = "0.5", features = ["all"] }
 -postgres-protocol = { version = "0.6.6", path = "../postgres-protocol" }
 -postgres-types = { version = "0.2.5", path = "../postgres-types" }
 -tokio = { version = "1.27", features = ["io-util"] }
++postgres-protocol = { version = "0.6.6" }
++postgres-types = { version = "0.2.5" }
 +tokio = { version = "0.2.2", package = "madsim-tokio", features = ["io-util"] }
  tokio-util = { version = "0.7", features = ["codec"] }
+ rand = "0.8.5"
+ whoami = "1.4.1"
+ 
+ [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
+ socket2 = { version = "0.5", features = ["all"] }
  
  [dev-dependencies]
  futures-executor = "0.3"
- criterion = "0.4"
+ criterion = "0.5"
  env_logger = "0.10"
 -tokio = { version = "1.0", features = [
 +tokio = { version = "0.2", package = "madsim-tokio", features = [
      "macros",
      "net",
      "rt",
diff --cc tokio-postgres/src/connect_socket.rs
index ae2359e7,f2713117..02dab3bd
--- a/tokio-postgres/src/connect_socket.rs
+++ b/tokio-postgres/src/connect_socket.rs
@@@ -10,63 -11,40 +11,43 @@@ use tokio::net::UnixStream
  use tokio::time;
  
  pub(crate) async fn connect_socket(
-     host: &Host,
+     addr: &Addr,
      port: u16,
      connect_timeout: Option<Duration>,
-     tcp_user_timeout: Option<Duration>,
+     #[cfg_attr(not(target_os = "linux"), allow(unused_variables))] tcp_user_timeout: Option<
+         Duration,
+     >,
      keepalive_config: Option<&KeepaliveConfig>,
  ) -> Result<Socket, Error> {
-     match host {
-         Host::Tcp(host) => {
-             let addrs = net::lookup_host((&**host, port))
-                 .await
-                 .map_err(Error::connect)?;
+     match addr {
+         Addr::Tcp(ip) => {
+             let stream =
+                 connect_with_timeout(TcpStream::connect((*ip, port)), connect_timeout).await?;
  
-             let mut last_err = None;
+             stream.set_nodelay(true).map_err(Error::connect)?;
  
-             for addr in addrs {
-                 let stream =
-                     match connect_with_timeout(TcpStream::connect(addr), connect_timeout).await {
-                         Ok(stream) => stream,
-                         Err(e) => {
-                             last_err = Some(e);
-                             continue;
-                         }
-                     };
- 
-                 stream.set_nodelay(true).map_err(Error::connect)?;
- 
-                 #[cfg(not(madsim))]
-                 let sock_ref = SockRef::from(&stream);
-                 #[cfg(target_os = "linux")]
-                 #[cfg(not(madsim))]
-                 {
-                     sock_ref
-                         .set_tcp_user_timeout(tcp_user_timeout)
-                         .map_err(Error::connect)?;
-                 }
- 
-                 #[cfg(not(madsim))]
-                 if let Some(keepalive_config) = keepalive_config {
-                     sock_ref
-                         .set_tcp_keepalive(&TcpKeepalive::from(keepalive_config))
-                         .map_err(Error::connect)?;
-                 }
++            #[cfg(not(madsim))]
+             let sock_ref = SockRef::from(&stream);
+             #[cfg(target_os = "linux")]
++            #[cfg(not(madsim))]
+             {
+                 sock_ref
+                     .set_tcp_user_timeout(tcp_user_timeout)
+                     .map_err(Error::connect)?;
+             }
  
-                 return Ok(Socket::new_tcp(stream));
++            #[cfg(not(madsim))]
+             if let Some(keepalive_config) = keepalive_config {
+                 sock_ref
+                     .set_tcp_keepalive(&TcpKeepalive::from(keepalive_config))
+                     .map_err(Error::connect)?;
              }
  
-             Err(last_err.unwrap_or_else(|| {
-                 Error::connect(io::Error::new(
-                     io::ErrorKind::InvalidInput,
-                     "could not resolve any addresses",
-                 ))
-             }))
+             Ok(Socket::new_tcp(stream))
          }
          #[cfg(unix)]
-         Host::Unix(path) => {
-             let path = path.join(format!(".s.PGSQL.{}", port));
+         Addr::Unix(dir) => {
+             let path = dir.join(format!(".s.PGSQL.{}", port));
              let socket = connect_with_timeout(UnixStream::connect(path), connect_timeout).await?;
              Ok(Socket::new_unix(socket))
          }

or git diff f989f42^2

trungda and others added 30 commits August 26, 2022 13:46
…cp-keepalive-options

OpenBSD misses some TCP keepalive options
refactor(types): improve readability of `impl ToSql for &str`
andrewbaxter and others added 29 commits July 20, 2023 22:54
…ismatch

feat(derive): add `#[postgres(allow_mismatch)]`
This mimics the behaviour of libpq and some other libraries (see rust-postgres#1024).
This commit uses the `whoami` crate, and thus goes as far as defaulting the user to the executing process' user name on all operating systems.
`tokio-postgres`: Set user to executing process' user by default.
@xxchan xxchan changed the title sync upstream sync upstream v0.19.7 Sep 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.